cmake_minimum_required (VERSION 2.8)
project (gateway_demo)

# 运行平台
SET(CMAKE_SYSTEM_NAME Linux)
# 交叉编译-指定工具链

#/home/mt/openwrt-23.05.2/staging_dir/toolchain-mipsel_24kc_gcc-12.3.0_musl/bin/mipsel-openwrt-linux-gcc
#交叉编译时打开此项
option(CROSS_COMPILE_SW_ENABLE "embed cross compile" OFF)
if(CROSS_COMPILE_SW_ENABLE)
#if(false)
	#SET(TOOLCHAIN_DIR "/opt/buildroot-gcc463/usr/bin/")
	#SET(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}mipsel-linux-gcc)
 
    SET(TOOLCHAIN_DIR "/home/mt/openwrt-23.05.2/staging_dir/toolchain-mipsel_24kc_gcc-12.3.0_musl/bin/")
    SET(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}mipsel-openwrt-linux-gcc)
endif()

# 编译选项
set(CMAKE_BUILD_TYPE "Debug")
set( CMAKE_C_FLAGS "-std=gnu99" )
# 执行文件存放路径
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)

# 交叉编译-库文件路径
if(CROSS_COMPILE_SW_ENABLE)
 
	LINK_DIRECTORIES(/home/mt/openwrt-23.05.2/staging_dir/target-mipsel_24kc_musl/usr/lib/)
    LINK_DIRECTORIES(/home/mt/openwrt-23.05.2/uild_dir/target-mipsel_24kc_musl/nghttp2-1.57.0/ipkg-install/usr/lib/)
    LINK_DIRECTORIES(/home/mt/openwrt-23.05.2/build_dir/target-mipsel_24kc_musl/zlib-1.2.13/ipkg-install/usr/lib/)
    LINK_DIRECTORIES(/home/mt/openwrt-23.05.2/build_dir/target-mipsel_24kc_musl/openssl-3.0.12/ipkg-install/usr/lib/)
    LINK_DIRECTORIES(/home/mt/openwrt-23.05.2/build_dir/target-mipsel_24kc_musl/nghttp2-1.57.0/lib/)
else()
    #LINK_DIRECTORIES(lib/)
    # 宿主机编译-库文件路径
    LINK_DIRECTORIES(/usr/local/lib/)
endif()


# 交叉编译-头文件路径
if(CROSS_COMPILE_SW_ENABLE)
#if(false)
    include_directories(/home/mt/openwrt-23.05.2/staging_dir/target-mipsel_24kc_musl/usr/include/)
    include_directories(/home/mt/openwrt-23.05.2/build_dir/target-mipsel_24kc_musl/zlib-1.2.13/ipkg-install/usr/include/)
    include_directories(/home/mt/openwrt-23.05.2/build_dir/target-mipsel_24kc_musl/curl-8.4.0/ipkg-install/usr/include/)
    include_directories(/home/mt/openwrt-23.05.2/build_dir/target-mipsel_24kc_musl/openssl-3.0.12/ipkg-install/usr/include/)
else()
    include_directories(lib/mosquitto/include)
    include_directories(lib/include)
endif()

# 工程内部头文件
include_directories(include)


if(CROSS_COMPILE_SW_ENABLE)
	set( THIRD_PARTY_LIBS 
    z
	nghttp2
    pthread
    curl
    m
    ssl
    crypto
    mosquitto
    sqlite3
    rt
)
else()
# 链接库名
set( THIRD_PARTY_LIBS 
    pthread
    curl
    m
    ssl
    crypto
    mosquitto
    sqlite3
    rt
)
endif()


aux_source_directory (./src DIR_SRCS)
aux_source_directory (../3rd_part/paho.mqtt.embedded-c-master/MQTTClient-C/src/linux DIR_MQTT_LINUX)
add_executable (run_demo ${DIR_SRCS})
target_link_libraries (run_demo ${THIRD_PARTY_LIBS})

